package com.ponhu.ea2.goodsCenter.bms.api.controller;

import com.ponhu.ea2.common.basic.model.ResponseBean;
import com.ponhu.ea2.dto.CloudTradeGoodsV2Dto;
import com.ponhu.ea2.dto.DictItemDataDto;
import com.ponhu.ea2.service.facade.CloudTradeGoodsManageService;
import com.ponhu.ea2.service.facade.CloudTradeService;
import com.ponhu.ea2.vo.CloudTradeGoodsDetailV2VO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Validated
@RestController
@RequestMapping("/goods/cloudTrade")
@Api(tags = "云商系统使用的接口", value = "GoodsCenterForCloudTradeController")
public class GoodsCenterForCloudTradeController {

    @DubboReference(version = "1.0.0", check = false)
    private CloudTradeService cloudTradeService;

    @DubboReference(version = "1.0.0", check = false)
    private CloudTradeGoodsManageService cloudTradeGoodsManageService;

    @ApiOperation(value = "根据云商渠道商品编码查询商品详细信息")
    @GetMapping("/getCloudTradeGoodsDetailByChannelGoodsCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channelGoodsCode", value = "云商渠道商品编码",
                    dataType = "string", paramType = "query", required = true)
    })
    public ResponseBean<CloudTradeGoodsDetailV2VO> getCloudTradeGoodsDetailByChannelGoodsCodeV2(@RequestParam @NotEmpty String channelGoodsCode) {
        return ResponseBean.ok(cloudTradeGoodsManageService.getCloudTradeGoodsDetailByChannelGoodsCodeV2(channelGoodsCode));
    }

    @ApiOperation(value = "根据云商渠道商品编码下架商品")
    @GetMapping("/downShelf")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channelGoodsCode", value = "云商渠道商品编码",
                    dataType = "string", paramType = "query", required = true)
    })
    public ResponseBean<Boolean> downShelf(@RequestParam @NotEmpty String channelGoodsCode) {
        return ResponseBean.ok(cloudTradeGoodsManageService.downShelf(channelGoodsCode));
    }

    @ApiOperation(value = "根据云商渠道商品编码上架商品")
    @GetMapping("/upShelf")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "channelGoodsCode", value = "云商渠道商品编码",
                    dataType = "string", paramType = "query", required = true)
    })
    public ResponseBean<Boolean> upShelf(@RequestParam @NotEmpty String channelGoodsCode) {
        return ResponseBean.ok(cloudTradeGoodsManageService.upShelf(channelGoodsCode));
    }

    @ApiOperation(value = "保存或更新字典项数据")
    @PostMapping("/addOrUpdateDictItem")
    public ResponseBean<Boolean> addOrUpdateDictItem(@RequestBody @NotEmpty List<@Valid DictItemDataDto> dictItemDataDtoList) {

        return ResponseBean.ok(cloudTradeService.addOrUpdateDictItem(dictItemDataDtoList));
    }

    @ApiOperation(value = "添加云商商品列表V2")
    @PostMapping("/addCloudTradeGoodsList")
    public ResponseBean<Boolean> addCloudTradeGoodsListV2(@RequestBody @NotEmpty(message = "云商商品信息列表不能为空") List<@Valid CloudTradeGoodsV2Dto> cloudTradeGoodsDtoList) {

        return ResponseBean.ok(cloudTradeService.addCloudTradeGoodsListV2(cloudTradeGoodsDtoList));
    }

    @ApiOperation(value = "更新云商商品V2")
    @PostMapping("/updateCloudTradeGoods")
    public ResponseBean<Boolean> updateCloudTradeGoodsV2(@RequestBody @Validated CloudTradeGoodsV2Dto cloudTradeGoodsDto) {

        return ResponseBean.ok(cloudTradeService.updateCloudTradeGoodsV2(cloudTradeGoodsDto));
    }

}
